package cn.iotab.iotkit.server.demo.device.handler;

import cn.iotab.iotkit.transport.api.access.handler.ToServerRpcHandler;
import cn.iotab.iotkit.transport.api.common.message.msg.rpc.AuthBasicRequestMsg;
import cn.iotab.iotkit.transport.api.common.message.msg.rpc.AuthResponseMsg;
import cn.iotab.iotkit.transport.api.common.message.msg.rpc.AuthX509RequestMsg;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MyRpcHandler implements ToServerRpcHandler {
    @Override
    public ListenableFuture<AuthResponseMsg> onBasicAuth(AuthBasicRequestMsg msg) {
        log.info("receive device AuthBasic req: {}", msg);
        AuthResponseMsg responseMsg = new AuthResponseMsg();
        responseMsg.setSuccess(true);
        responseMsg.setProductKey("aaa");
        responseMsg.setDeviceId("bbb");
        //
        SettableFuture<AuthResponseMsg> future = SettableFuture.create();
        future.set(responseMsg);
        return future;
    }

    @Override
    public ListenableFuture<AuthResponseMsg> onX509Auth(AuthX509RequestMsg msg) {
        log.info("receive device onX509Auth req: {}", msg);
        AuthResponseMsg responseMsg = new AuthResponseMsg();
        responseMsg.setSuccess(true);
        //
        SettableFuture<AuthResponseMsg> future = SettableFuture.create();
        future.set(responseMsg);
        return future;
    }

}
